package com.xiaoshuidi.cloud.module.report.controller.bigdata;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.report.controller.bigdata.vo.PaymentOutflowRatioVO;
import com.xiaoshuidi.cloud.module.report.controller.bigdata.vo.ReceiptInflowVO;
import com.xiaoshuidi.cloud.module.report.controller.bigdata.vo.TransactionDetailsVO;
import com.xiaoshuidi.cloud.module.report.controller.bigdata.vo.YearMonthRevenueVO;
import com.xiaoshuidi.cloud.module.report.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.report.service.bigdata.OverviewTransactionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import java.util.Date;
import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;


/**
 * 交易数据概览
 */
@Slf4j
@RestController
@RequestMapping(ApiConstants.PREFIX + "/overviewTransaction")
@Validated
@PermitAll
public class OverviewTransactionController {

    @Resource
    private OverviewTransactionService overviewTransactionService;


    /**
     * 获得付款流出数据
     *
     * @param startTime 开始时间 yyyy-MM-dd
     * @param endTime   结束时间 yyyy-MM-dd
     * @param aptId     公寓id
     * @return {@link CommonResult}<{@link PaymentOutflowRatioVO}>
     */
    @GetMapping("/getPaymentOutflowData")
    public CommonResult<PaymentOutflowRatioVO> getPaymentOutflowData(@DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "startTime",required = false)  Date startTime,
                                                                     @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "endTime",required = false)Date endTime
                                                                    , @RequestParam(value = "aptId",required = false)Long aptId) {
        return success(overviewTransactionService.getPaymentOutflowData(startTime,endTime,aptId));
    }


    /**
     * 年月收入统计 /万元
     *
     * @return {@link CommonResult}<{@link List}<{@link YearMonthRevenueVO}>>
     */
    @GetMapping("/getYearMonthRevenueStatistics")
    public CommonResult<List<YearMonthRevenueVO>> getYearMonthRevenueStatistics() {
        return success(overviewTransactionService.getYearMonthRevenueStatistics());
    }



    /**
     * 获取收款流入数据
     *
     * @param startTime 开始时间 yyyy-MM-dd
     * @param endTime   结束时间 yyyy-MM-dd
     * @param aptId     公寓id
     * @return {@link CommonResult}<{@link ReceiptInflowVO}>
     */
    @GetMapping("/getReceiptInflowData")
    public CommonResult<ReceiptInflowVO> getReceiptInflowData(@DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "startTime",required = false)  Date startTime,
                                                                     @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "endTime",required = false)Date endTime
            , @RequestParam(value = "aptId",required = false)Long aptId) {
        return success(overviewTransactionService.getReceiptInflowData(startTime,endTime,aptId));
    }


    /**
     * 获取交易明细
     *
     * @param startTime 开始时间 yyyy-MM-dd
     * @param endTime   结束时间 yyyy-MM-dd
     * @param aptId     公寓id
     * @return {@link CommonResult}<{@link TransactionDetailsVO}>
     */
    @GetMapping("/getTransactionDetails")
    public CommonResult<TransactionDetailsVO> getTransactionDetails(@DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "startTime",required = false)  Date startTime,
                                                                    @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "endTime",required = false)Date endTime
            , @RequestParam(value = "aptId",required = false)Long aptId) {
        return success(overviewTransactionService.getTransactionDetails(startTime,endTime,aptId));
    }
}
